package com.nts.bupna.generator;

import static com.nts.bupna.util.StringUtil.concat;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class Generator {
    private static Logger log = LoggerFactory.getLogger(Generator.class);

    private final List<String> lines  = new ArrayList<String>();

    private String indent = "";
    private final String indentSize = "    ";

    String done() {
        if (log.isDebugEnabled()) {
            List<String> numbered = new ArrayList<String>(lines.size());
            int i = 1;
            for (String string : lines) {
                numbered.add(i++ + "\t" + string);
            }
            log.debug("\n{}", concat(numbered));
        }
        return concat(lines);
    }

    void line() {
        lines.add("");
    }

    void line(final String line) {
        lines.add(indent + line);
    }

    void r() {
        indent += indentSize;
    }

    void l() {
        indent = indent.substring(0, indent.length() - indentSize.length());
    }
}
